var shengSelect = document.querySelector('.sheng');
var shiSelect = document.querySelector('.shi');
var quSelect = document.querySelector('.qu');

var shenglist = ['江西', '广东', '湖北', '湖南'];
var shilist = [['南昌', '九江', '赣江'], ['广州', '深圳', '东莞'], ['武汉', '荆门', '襄阳'], ['长沙', '邵阳', '株州']];
var qulist = [
    [['南1区', '南2区', '南3区'], ['九1区', '九2区', '九3区'], ['赣1区', '赣2区', '赣3区']],
    [['广1区', '广2区', '广3区'], ['深1区', '深2区', '深3区'], ['东1区', '东2区']],
    [['武1区', '武2区', '武3区'], ['荆1区', '荆2区', '荆3区'], ['襄1区', '襄2区', '襄3区']],
    [['岳麓区', '雨花区', '天心区'], ['隆回', '邵阳', '塘渡口'], ['珠江河', '火车站', '高铁站']]
];

var index = 0;//下标

//省
for (var i = 0; i < shenglist.length; i++) {
    var shengOption = new Option(shenglist[i]);
    shengSelect.options.add(shengOption);
}

//省
shengSelect.onchange = function (ev) {
    // console.log(ev);
    index = ev.target.selectedIndex - 1;
    // console.log(index);
    if (index == -1) {
        //选择“请选择”,让市区列表为空
        shiSelect.options.length = 0;
        quSelect.options.length = 0;
    } else {
        //再次作选择时，让市区列表为空，好重新获取市区数据
        shiSelect.options.length = 0;
        quSelect.options.length = 0;
        //在点击省时，给市添加option
        for (var j = 0; j < shilist.length; j++) {
            console.log(shilist[index][j]);
            var shiOption = new Option(shilist[index][j]);
            shiSelect.options.add(shiOption);
        }
        //给区添加option
        for (var k = 0; k < qulist[index][0].length; k++) {
            var quOption = new Option(qulist[index][0][k]);
            quSelect.options.add(quOption);
        }
    }
};

//市
shiSelect.onchange = function (e) {
    var indexs = e.target.selectedIndex;
    //再次选择时，让区的列表为空，重新获取区的数据
    quSelect.options.length = 0;
    //点击市时，给区添加option
    for (var i = 0; i < qulist[index][indexs].length; i++) {
        var quOption = new Option(qulist[index][indexs][i]);
        quSelect.options.add(quOption);
    }
}


//计算商品价格
function productCount(){
var total = 0
//1.获取所有的行
var trs = document.getElementsByClassName('shopping_product_list')
// console.log(trs);
for(var i = 0 ; i < trs.length ; i++){
//2.计算每一行商品的价格和数量
var price  = trs[i].children[4].firstElementChild.innerHTML

var num = trs[i].children[3].firstElementChild.value

total += parseFloat(price * num)
}
console.log(price);
console.log(num);

//3.显示结果
document.getElementById('product_total').innerHTML = total
document.getElementById('product_total1').innerHTML = total
}
productCount()



// var info
// function show(){
//     var select=document.querySelector('#sheng')
//     var select=document.querySelector('#shi')
//     var select=document.querySelector('#qu')
//     select.onchange=function(){

//         info=this.options[this.selectedIndex].text
//     }

// }
// show()

// function exec(){
//     document.querySelector('#message').innerHTML=info


// }
